<?php
  define("MIN_BYET_LENGTH", 200000); //~200kb
  class CheckUrl extends Proxy {
    private $data;
    private $result;
    
    public function CheckUrl($url){
        $this->curl = curl_init();
  
        curl_setopt($this->curl, CURLOPT_URL, $url);
        curl_setopt($this->curl, CURLOPT_HEADER, true);
        curl_setopt($this->curl, CURLOPT_NOBODY, true);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($this->curl, CURLOPT_MAXREDIRS, 10); //follow up to 10 redirections - avoids loops
  
        $this->data = curl_exec($this->curl);
  
        curl_close($this->curl);
    }
    
    public function search($a=null,$b=null){
        //echo $data;
        //Content-Length: 1635 Content-Type: text/html 
        //preg_match("/HTTP\/1\.[1|0]\s+(\d{3})/i",$data,$m);//[\w\s\d]*Content-Length:\s+(\d+)
        //print_r ($m);
        
        if(!$this->data)
          $this->result = 'Domain not found';
  
        preg_match("/HTTP\/1\.[1|0]\s+(\d{3})/i",$this->data,$m);
        if($m[1] != 200)
          $this->result = 'Page not found: '.$m[1].' error code';
  
        preg_match("/Content-Type:\s+([\w\/]+)/i",$this->data,$m);
        if($m[1] != 'audio/mpeg')
          $this->result = 'File not in mpeg layer 3 format (MP3)';
  
        preg_match("/Content-Length:\s+([\d]+)/i",$this->data,$m);
        if($m[1] < MIN_BYET_LENGTH)
          $this->result = 'File too small. Minimum length is ~200Kb';
  }
  
  public function send(){
    if($this->result == null)
      $msg = '<proxy id="response">OK</proxy>';
    else $msg = '<proxy id="response">'.$this->result.'</proxy>';
  }
 }
?>
